import tailwindcss from '@tailwindcss/vite'
import { tanstackRouter } from '@tanstack/router-plugin/vite'
import react from '@vitejs/plugin-react-swc'
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'

// https://vite.dev/config/
export default defineConfig(({  mode }) => {
  console.log('%c Line:9 🍉 mode', 'color:#ed9ec7', mode)
  return {
    plugins: [
      tanstackRouter({
        target: 'react',
        autoCodeSplitting: true,
      }),
      react(),
      tailwindcss(),
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '@assets': resolve(__dirname, './src/assets'),
        '@conf': resolve(__dirname, './src/conf'),
        '@components': resolve(__dirname, './src/components'),
        '@hooks': resolve(__dirname, './src/hooks'),
        '@services': resolve(__dirname, './src/services'),
        '@utils': resolve(__dirname, './src/utils'),
      },
    },
    base: './',
    build: {
      outDir: 'admin',
    },
    server: {
      port: 3000,
      open: true,
      proxy: {
        '/api': {
          target: loadEnv(mode, process.cwd(), '').VITE_APP_HOST,
          changeOrigin: true,
        },
        '/sanctum': {
          target: loadEnv(mode, process.cwd(), '').VITE_APP_HOST,
          changeOrigin: true,
        },
      },
    },
  }
})
